//初始化index页头
$(function() {
	var uid = localStorage.getItem("shipinUid");
    var token = localStorage.getItem("token"); //added by 董瑞贤 at 2016.12.8
	tr = "";
	tr += "<div id=\"top\">";
	tr += "<div class=\"wp\">";
	tr += "<div class=\"r\" id=\"top-con\">";
	
	if(uid) {
		tr += "<span>400-9009365</span>";
		tr += "<a href=\"gerenzhongxin.html\" class=\"ico\">个人中心</a>|";
		tr += "<div id=\"tuichu\" onclick=\"tuichu();\">已登录，退出</div>";
	}else {
		tr += "<span>400-9009365</span>";
		tr += "<a class=\"pl10\" href=\"login.html?type=2\">登录</a>/";
		tr += "<a href=\"login.html?type=2\">注册</a>";
	}
	tr += "</div>";
	tr += "</div>";
	tr += "</div>";
	tr += "<div id=\"hd\">";
	tr += "<div class=\"wp\">";
	tr += "<div class=\"logo\">";
	tr += "<a href=\"index.html\"><img src=\"images/logo_03.jpg\" alt=\"\"></a>";
	tr += "</div>";
//	tr += "<div class=\"search\">";
//	tr += "<form action=\"\" class=\"\">";
//	tr += "<input type=\"text\" placeholder=\"搜索课程\" name=\"/\" id=\"scon\" class=\"inp\">";
//	tr += "<div name=\"\" onclick=\"sousuo();\" class=\"inp1\"></div>";
//	tr += "</form>";
//	tr += "</div>";
	tr += "<div class=\"sign-in\">";
//	tr += "<div class=\"sign-con\" onclick=\"qiandao();\" style=\"cursor: pointer;\"><img src=\"images/qiandao_03.jpg\" /><div class=\"signing\" id=\"s-ed\">签到</div><div id=\"s-in\" class=\"signing\" style=\"display:none;\">已签到</div></div>";
	tr += "<div class=\"day-num\" style=\"display:none;\"></div>";
	tr += "</div>";
	tr += "</div>";
	tr += "</div>";
	tr += "<div class=\"h\"></div>";
	tr += "<div class=\"wp\">";
	tr += "<div class=\"nav\">";
	tr += "<ul class=\"top-title\"></ul>";
	tr += "</div>";
	tr += "</div>";
	$("#index_top").html(tr);
	
	//签到
	var datanow = new Date();
	var month = datanow.getMonth()+1;
	if(month<10) {
		month = "0"+month;
	}
	var date = datanow.getDate();
	if(date<10) {
		date = "0"+date;
	}
	var t=datanow.getFullYear()+"-"+month+"-"+date;
	if(uid) {
		var actions = "/appSPersonalInformation/slectInfoByUid.ph?uid="+uid+"&token="+token+"&updateVersion=notUpdate";
		ajaxWeb(actions, null, function(datas) {
			var obj = datas.resobj;
			var qiantime = obj.qiantime;
			if(obj.name!=null&&obj.name!=""){
				$("#tuichu").html("您好，"+obj.name+"。  退出");
			}else{
				$("#tuichu").html("已登录，退出");
			}
			var sss = 0;
			if(obj.qiandaoday!=""&&obj.qiandaoday!=null){
				sss = obj.qiandaoday;
			}
			if(qiantime) {
				var qiantimes = qiantime.split(" ");
				var qd = qiantimes[0];
				if(t==qd) {
					$("#s-ed").hide();
					$("#s-in").show();
					$(".day-num").html("已经连续签到"+sss+"天");
					$(".day-num").show();
				}else {
					$("#s-ed").show();
					$("#s-in").hide();
					$(".day-num").html("已经连续签到"+sss+"天");
					$(".day-num").show();
				}
			}else {
				$("#s-ed").show();
				$("#s-in").hide();
				$(".day-num").html("已经连续签到"+sss+"天");
				$(".day-num").show();
			}
		},'json')	
	}
	
	//导航
	var action1 = "/appsfenlei/SFenlei.ph";
	//var action1 = "/liqiang365/SFenlei.ph";
	ajaxWeb(action1, null, function(data1) {
		var tr = "";
		var obj1 = data1.resobj.fenleis;
		if(data1.code=="40000") {
			for(var i=0;i<obj1.length;i++) {
				tr += "<li class=\"li_\">";
				tr += "<div class=\"yiji_\"><a class=\"s1\" href=\"javascript:void(0);\">"+obj1[i].name+"</a></div>";
				tr += "<dl class=\"erji_\">";
				tr += "<dd>";
				tr += "<em></em>";
				var action2 = "/appsfenlei/selectSFenleiTwo.ph?fflid="+obj1[i].zjid+"";
					//action2 = "/liqiang365/selectSFenleiTwo.ph?fflid="+obj1[i].zjid+"";
				ajaxPostAsyncData(action2, null, function(data2) {
					var obj2=data2.resobj;
					if(data2.code=="40000") {
						for(var j=0;j<obj2.length;j++) {
							if(j==(obj2.length-1)) {
								tr += "<a href=\"kecheng.html?zjid="+obj2[j].zjid+"&fflid="+obj2[j].fflid+"\">"+obj2[j].name+"</a>";
							}else {
								tr += "<a href=\"kecheng.html?zjid="+obj2[j].zjid+"&fflid="+obj2[j].fflid+"\">"+obj2[j].name+"</a>|";
							}
						}
					}
				},'json')
				//tr += "<a href="">自我成长</a>";
				tr += "</dd>";
				tr += "</dl>";
				tr += "</li>";
			}
		}
		$(".top-title").html(tr);
		//显示二级分类
		showerji();
	},'json')
});

//显示二级分类
function showerji(index) {
	$(".li_").hover(function() {
		$(this).children(".erji_").show();
	},function() {
		$(this).children(".erji_").hide();
	});
}

//退出操作
function tuichu() {
	localStorage.setItem("shipinUid","");
	window.location.href="index.html";
}

//签到
function qiandao() {
	var uid = localStorage.getItem("shipinUid");
    var token = localStorage.getItem("token"); //added by 董瑞贤 at 2016.12.8
	if(uid) {
		var action5 = "/appSPersonalInformation/updateQiandao.ph?uid="+uid+"&token="+token+"&updateVersion=notUpdate";
		ajaxWeb(action5, null, function(data5) {
			if(data5.code=="40000") {
				var actions = "/appSPersonalInformation/slectInfoByUid.ph?uid="+uid+"&token="+token+"&updateVersion=notUpdate";
				ajaxPostAsyncData(actions, null, function(datas) {
					var obj = datas.resobj;
						$("#s-ed").hide();
						$("#s-in").show();
						$(".day-num").html("已经连续签到"+obj.qiandaoday+"天");
						$(".day-num").show();
						$.jBox.tip('签到成功', 'success');
				},'json')
			}else if(data5.code=="40012") {
				$.jBox.tip('今天已签到', 'error');
				return false;
			}else {
				$.jBox.tip('签到失败', 'error');
				return false;
			}
		},'json')
	}else {
		$.jBox.tip('请先登录', 'error');
		return false;
	}
}

//内容搜索
function sousuo() {
	var content = $("#scon").val();
	localStorage.setItem("kecheng",content);
	window.location.href="gengduo.html";
}